import Mock from 'mockjs'

// 模拟用户列表数据
Mock.mock(/\/mock\/userdetail.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  let num = 45 - (body.page - 1) * 8
  num = num > 8 ? 8 : num
  let data = Mock.mock({
    [`list|${num}`]: [{
      'id|+15': 200761,
      wechat: '@word(5,8)',
      'name|1': ['张三','李四','陈二','毛毛','小二','大头','小七','黄超'],
      'sex|1': ['男', '女'],
      phone: Mock.mock(/1\d{10}/),
      address: Mock.Random.county(),
      time: '@DATETIME("yyyy-MM-dd HH:mm")',
      'surplus|1-50': 0,
      'consumption|0-100': 0,
      'balance|1-1000': 0,
      birthday: '1988-1-8',
      height: '180cm',
      width: '55kg',
      score: '999',
      money: '560',
      regTime: '2021-1-9'
    }],

    total: 45,
    pageSize: 8,
    isEnd: false,
    message: '请求用户列表数据成功',
  })

  if (body.value) {
    let jiz=/^1/.test(body.value)
    if (!isNaN(body.value)) {
      //@ts-ignore
      if (jiz) {
        //@ts-ignore
        data.list = data.list.map((item) => {
          console.log(item)
          item.phone = body.value
          return item
        })
        data.total *=0.5
      }else{
           //@ts-ignore
           data.list = data.list.map((item) => {
            console.log(item)
            item.id = body.value
            return item
          })
          data.total *=0.5
      }
    }
  
    else{ 
      let namelist =['张三','李四','陈二','毛毛','小二','大头','小七','黄超']
      namelist=  namelist.filter(item=>{
        return item.includes(body.value)
      })
      if(namelist[0]){
        // @ts-ignore
        data.list = data.list.map((item) => {
         const num = Math.floor(Math.random()*namelist.length)
          item.name = namelist[num]
          return item
        })
        data.total *= namelist.length/3
       
      }
      else{
        data.list=[]
      }


     
    }

  }
  return {
    data,
    code: 200,
    message: '请求用户列表数据成功',
  }
})


// 模拟订单记录数据
Mock.mock(/\/mock\/user-orderhistory.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  let num = 45 - (body.page - 1) * 10
  num = num > 10 ? 10 : num
  let data = Mock.mock({
    [`list|${num}`]: [{
      orderNumber: Mock.mock(/2022\d{6}/),
      'orderProduct|1': ['男士餐', '女士餐', '工作餐'],
      'orderMoney|50-1000': 0,
      adress: '肖家河大厦千锋教育',
      paymentState: '已支付',
      orderState: '进行中',
      consignee: Mock.Random.cname(),
      consigneePhone: Mock.mock(/1\d{10}/),
      orderTime: '@DATETIME("yyyy-MM-dd HH:mm")',
    }],
    total: 45,
    pageSize: 10,
    message: '请求订单记录数据成功',
  })

  if (body.value) {
    // @ts-ignore
    data.list = data.list.map(item => {
      item.orderProduct = body.value
      return item
    })
    data.total *= 0.3
  }

  return {
    data,
    code: 200,
    message: '请求订单记录数据成功',
  }
})

// 模拟配送记录数据
Mock.mock(/\/mock\/user-distributionhistory.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  let num = 45 - (body.page - 1) * 8
  num = num > 8 ? 8 : num
  let data = Mock.mock({
    [`list|${num}`]: [{
      'goods|1': ['男士餐', '女士餐', '工作餐'],
      distributionTime: '@DATETIME("yyyy-MM-dd HH:mm")',
      distributionAddress: '千锋教育',
      'state|1': ['已配送', '未配送', '配送中', '已取消', '已退款'],
      remarks: '',
    }],
    total: 45,
    pageSize: 8,
    message: '请求配送记录数据成功',
  })
  if (body.value) {
    // @ts-ignore
    data.list = data.list.map(item => {
      item.goods = body.value
      return item
    })
    data.total *= 0.3
  }
  return {
    data,
    code: 200,
    message: '请求配送记录数据成功',
  }
})

// 模拟更改记录数据
Mock.mock(/\/mock\/timerecord.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  console.log(body)
  const data = Mock.mock({
    'list|5': [{
      'name|1': ['男士餐', '女士餐', '工作餐'],
      originalTime: 20,
      admindNumber: +3,
      amendTime: 23,
      surplus: '无改变',
      adminCouse: '无',
      adminMin: '@DATETIME("yyyy-MM-dd HH:mm")',
      admin: '大宝',
    }],
    total: 5,
    isEnd: false,
    message: '请求更改记录数据成功',
  })
  if (body.value) {
    // @ts-ignore
    data.list = data.list.map(item => {
      item.name = body.value
      return item
    })
  }
  return {
    data,
    code: 200,
    message: '请求更改记录数据成功',
  }
})

// 模拟修改用户信息数据
Mock.mock(/\/mock\/edituser.*/, 'post', (options: any) => {
  const data = {
    code: 200,
    message: '修改用户信息成功',
  }
  return {
    data,
    code: 200,
  }
})

//体重
Mock.mock(/\/mock\/weight.*/, 'post', (options: any) => {
  let num = 45 - (options.body - 1) * 8
  num = num > 8 ? 8 : num
  const data = Mock.mock({
    [`list|${num}`]: [{
      check: false,
      time: '@DATETIME("yyyy-MM-dd HH:mm")',
      weight: '68kg',
    }],
    total: 40,
    pageSize: 8,
    isEnd: false,
  })

  return {
    data,
    code: 200,
    message: '体重记录列表成功',
  }
})
//提现
Mock.mock(/\/mock\/withdrawal.*/, 'post', (options: any) => {
  let num = 45 - (options.body - 1) * 8
  num = num > 8 ? 8 : num
  const data = Mock.mock({
    [`list|${num}`]: [{
      check: false,
      time: '@DATETIME("yyyy-MM-dd HH:mm")',
      money: '500元',
      'state|1': ['已打款', '未打款'],
    }],
    total: 50,
    pageSize: 8,
    isEnd: false,
  })

  return {
    data,
    code: 200,
    message: '提现记录列表成功',
  }
})
//优惠券
Mock.mock(/\/mock\/usercoupon.*/, 'post', (options: any) => {
  let num = 45 - (options.body - 1) * 8
  num = num > 8 ? 8 : num
  const data = Mock.mock({
    [`list|${num}`]: [{
      check: false,
      'id|+1': 1,
      'name|1': ['20元优惠券', '50元优惠券', '100元优惠券'],
      'type|1': ['指定范围', '通用'],
      'range|1': ['男士', '女士', '通用'],
      'condition|1': ['购物满50', '购物满100', '通用'],
      'money|1': ['50', '100', '150'],
      'surplus|1': ['是', '否'],
      'consumption|1': ['100', '200'],
      balance: '@DATETIME("yyyy-MM-dd")',
    }],
    total: 30,
    pageSize: 8,
    isEnd: false,
  })

  return {
    data,
    code: 200,
    message: '优惠券列表成功',
  }
})

//充值
Mock.mock(/\/mock\/recharge.*/, 'post', (options: any) => {
  let num = 45 - (options.body - 1) * 8
  num = num > 8 ? 8 : num
  const data = Mock.mock({
    [`list|${num}`]: [{
      check: false,
      time: '@DATETIME("yyyy-MM-dd HH:mm")',
      money: '500元',
      'state|1': ['已付款', '未付款'],
    }],
    total: 30,
    pageSize: 8,
    isEnd: false,
  })

  return {
    data,
    code: 200,
    message: '充值记录列表成功',
  }
})
//配送
Mock.mock(/\/mock\/delivery.*/, 'post', (options: any) => {
  let num = 45 - (options.body - 1) * 8
  num = num > 8 ? 8 : num
  const data = Mock.mock({
    [`list|${num}`]: [{
      check: false,
      'order|+1': 2017001,
      'commodity|1': ['男士餐', '女士餐', '工作餐'],
      time: '@DATETIME("yyyy-MM-dd HH:mm")',
      add: Mock.Random.city(true),
      'state|1': ['已配送', '未配送'],
      note: '无',
    }],
    total: 30,
    pageSize: 8,
    isEnd: false,
  })

  return {
    data,
    code: 200,
    message: '配送商品列表成功',
  }
})